home *** CD-ROM | disk | FTP | other *** search
- Path: news.zipnet.net!usenet
- From: lindak@pumpkin.iii.net (Linda Kasparek)
- Newsgroups: comp.lang.c++
- Subject: Re: C++ Read Comma Delimted Text File
- Date: 7 Apr 1996 15:56:00 GMT
- Organization: iii.net subscriber
- Message-ID: <4k8oig$hov@news.zipnet.net>
- References: <4k3j9u$jaj$1@mhadg.production.compuserve.com>
- Reply-To: jmk@tiac.net
- NNTP-Posting-Host: ip19-max1-fitch.zipnet.net
- X-Newsreader: WinVN 0.92.6+
-
-
- I've just done this myself... getline() is an istream function that reads everything up to a delimiter you specify
- (defaulting to the newline character '/n' if you don't) into a character buffer. The delimiter is extracted
- but not copied to the buffer. (get() neither extracts nor copies the delimiter character into your buffer.)
- Then, I just strtok through the buffer in a for loop using ',' as the delimiter. In my case, depending on the index
- number of the for loop, I populate a structure field with the appropriate token.
-
- (The reference I used was Steve Teale's C++ IOStreams Handbook.)
-
- Hope this helps.
-
- Linda
-
-
- In article <4k3j9u$jaj$1@mhadg.production.compuserve.com>, Steve Farson <75226.1623@CompuServe.COM> says:
- >
- >I've never seen or heard of any example showing how to read a
- >comma delimted text file looking something like this:
- >
- >ABC,13,12.3,Houston
- >DEF,4,11.4,Denver
- >EFG,21,14.7,Phoenix
- >
- >into variables. I have a C program doing this, but think there
- >surely is some C++ functions that can help here. Someone
- >mentioned Getline() once, but every reference I have says nothing
- >about how it would/could be used. If anyone could provide a
- >snippet or two on how this is done, it would be great.
- >
- >Thanks! Steve
-